import { createWebHistory, createRouter } from 'vue-router';
import Login from '../page/login/index.vue';
import { useCommonStore } from '../store';



// const Home = () => import('../page/main/mainContent.vue')
const Mapbj = () => import('../page/main/mapbj.vue')
const Home = () =>import('../page/main/滚动指定位置.vue') 
const Three = () => import('../page/main/three.vue')
const Clock_ = () => import('../page/main/clock.vue')
const First3d = () => import('../page/main/first3d.vue')
const Parent = () => import('../../src/子父传值/parent.vue')
const Son = () => import('../../src/子父传值/son.vue')
export const router = createRouter({
    history:createWebHistory(),
    routes:[
        {path: '/', component:Login, meta: {nologin: true}},
        {path:'/home',component: Home},
        {path:'/map',component:Mapbj},
        {path:'/three',component:Three,meta: {nologin: true}},
        {path:'/clock',component:Clock_,meta: {nologin: true}},
        {path:'/f3d',component:First3d,meta: {nologin: true}},
        {path:'/parent',component:Parent,meta: {nologin: true}},
        {path:'/son',component:Son,meta: {nologin: true}},

    ]
})
// const router = createRouter({
//         history:createWebHistory(),
//         routes:[
//             {path: '/', component:Login, meta: {nologin: true}},
//             {path:'/home',component: Home},
//             {path:'/map',component:Mapbj}
//         ]
//     })

router.beforeEach((to, from, next) => {
    if(to.meta.nologin){
        next()
    }
    
    let token = useCommonStore().token;

    if (!!token) {
        next()
    } else {
        next('/')
    }
})

// export default router;
